<template>
    <view class="settings">
        <view class="titel">资料信息 </view>
        <view class="list">
            <view class="list-item">
                <view class="item-left">
                    账户
                </view>
                <view class="item-right">
                    {{userInfo.nickName}}
                </view>
            </view>
            <view class="list-item" hover-class="itemActive" @click="openReal()">
							<view class="item-left">
									实名
							</view>
							<view class="item-right flex alcenter">
									<view v-if="userInfo.is_real && userInfo.is_advanced === 1" >
										已完成认证
									</view>
									<view v-if="userInfo.is_real != 1" >
										未认证
									</view>
									
									<view v-if="userInfo.is_real === 1 && userInfo.is_advanced!=1" >
										请高级认证
									</view>
									 <image src="../../static/left2@2x.png" class="left2"></image>
							</view>
            </view>
            <view class="list-item" hover-class="itemActive" @click="openWithdrawAccount">
                <view class="item-left">
                    提现账号
                </view>
                <view class="item-right">
                    管理 <image src="../../static/left2@2x.png" class="left2"></image>
                </view>
            </view>
<!--            <view class="list-item" hover-class="itemActive">
                <view class="item-left">
                    交易密码
                </view>
                <view class="item-right">
                    设置 <image src="../../static/left2@2x.png" class="left2"></image>
                </view>
            </view> -->
            <view class="list-item" hover-class="itemActive" @click="openEditPass">
                <view class="item-left">
                    登录密码
                </view>
                <view class="item-right">
                    设置 <image src="../../static/left2@2x.png" class="left2"></image>
                </view>
            </view>
        </view>
        <view class="titel">其他信息 </view>
        <view class="list">
            <view class="list-item" @click="openBingPhone">
                <view class="item-left">
                    绑定手机
                </view>
                <view class="item-right">
                    {{userInfo.phone?$fxLink.checkHide(userInfo.phone):""}}<image src="../../static/left2@2x.png" class="left2"></image>
                </view>
            </view>
            <view class="list-item">
                <view class="item-left">
                    注册时间
                </view>
                <view class="item-right">
										{{userInfo.create_time}}
                </view>
            </view>
            <view class="list-item" hover-class="itemActive" @click="openWrite">
                <view class="item-left">
                    注销账号
                </view>
                <view class="item-right">
                    注销后清空数据<image src="../../static/left2@2x.png" class="left2"></image>
                </view>
            </view>
            <view class="list-item" hover-class="itemActive" @click="logOut">
                <view class="item-left">
                    退出登录
                </view>
                <view class="item-right">
                    <image src="../../static/left2@2x.png" class="left2"></image>
                </view>
            </view>
        </view>
        
    </view>
</template>

<script>
	import EvanSwitch from '@/components/evan-switch/evan-switch.vue'
	import * as Api from'@/api/user'
	export default{
		data(){
			return{
				userInfo:{},
				message:"1",
				codeMessage:'1',
				logoutDetail:{}
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.userList()
			this.logouttype()
			// this.getReceptionMessage()
		},
		methods:{
			openEditPass(){
				uni.navigateTo({
					url:'/pages/my/setting/editPass'
				})
			},
			openReal(){
				uni.navigateTo({
					url:"/pages/my/authentication"
				})
			},
			logOut(){
				uni.showModal({
					title:"温馨提示",
					content:"确认要退出吗？",
					// showCancel:false,
					success: (res) => {
						if(res.confirm){
							uni.clearStorageSync()
							uni.switchTab({
								url:"/pages/index/index"
							})
						}
					}
				})
			},
			logouttype(){
				Api.logouttype()
				.then(result => {
					this.logoutDetail = result.data
				})
			},
			logouecontent(){
				return new Promise((relove,reject) => {
					Api.logouecontent()
					.then(result => {
						relove(result)
					})
				})
			},
			async openWrite(){
				if(Number(this.logoutDetail.is_delete) === 1){
					let content = await this.logouecontent()
					let _this = this
					uni.showModal({
						title:"提示",
						content:content.data.content,
						cancelText:"取消",
						confirmText:"确认注销",
						confirmColor:"#0eb6ff",
						success: (res) => {
							if(res.confirm){
								Api.closeAcc({token:uni.getStorageSync("AccessToken")}).then(result => {
									this.logouttype()
									if(result.code === 1){
										_this.$toast('注销成功')
										setTimeout(() => {
											uni.redirectTo({
												url:"/pages/logout"
											})
										},1000)
									}else{
										_this.$toast(result.msg)
									}


								})
							}
						}
					})
				}else{
					uni.showModal({
						title:"提示",
						content:`${this.logoutDetail.logout_time}即将注销成功`,
						cancelText:"取消",
						confirmText:"恢复账号",
						confirmColor:"#0eb6ff",
						success: (res) => {
							if(res.confirm){
								Api.recoveryuser({token:uni.getStorageSync("AccessToken")}).then(result => {
									this.logouttype()
									if(result.code === 1){
										_this.$toast("恢复成功")
									}else{
										_this.$toast(result.msg)
									}
								})
							}
						}
					})
				}

			},
			openBingPhone(){
				if(this.userInfo.phone){
					uni.navigateTo({
						url:"/pages/my/setting/editPhone"
					})
				}else{
					uni.navigateTo({
						url:"/pages/my/setting/bind_phone"
					})
				}
			},
			openWithdrawAccount(){
				uni.navigateTo({
					url:"/pages/my/withdrawAccount/index"
				})
			},
			getReceptionMessage(){
				let _this = this
				let token = uni.getStorageSync("AccessToken")
				Api.getReceptionMessage({
					wxapp_id: _this.$wxapp_id,
					token: token,
				}).then(res => {
					this.message = String(res.data.is_message) 
				})
			},
			save_sms(){
				Api.save_sms({
					is_sms:Number(this.codeMessage)
				})
				.then(result => {
					if(result.code === 1){
						this.$toast(result.msg)
						this.userList()
					}else{
						this.$toast("更改失败")
					}
				})
			},
			set(){
				let message = Number(this.message)
				let _this = this
				let token = uni.getStorageSync("AccessToken")
				Api.setReception({
					is_message:message,
					wxapp_id: _this.$wxapp_id,
				}).then(res => {
					if(res.code === 1){
						
					}else{
						this.$toast('更改失败')
					}
				})
			},
			userList() {
				let _this = this;
				let token = uni.getStorageSync("AccessToken")
				Api.userInfo({
						wxapp_id: _this.$wxapp_id,
					})
					.then(result => {
						if(result.code === 1){
							_this.userInfo = result.data;
							console.log(this.userInfo);
							_this.codeMessage = String(result.data.is_sms) 
							uni.setStorageSync('userInfo',result.data);
						}
						
					}).catch(err => {
					})
			},
		}
	}
</script>

<style lang="scss">
    .left2{
        margin-left: 10rpx;
        width: 15rpx;
        height: 24rpx;
    }
    .settings{
        height: calc(100vh - 44px);
        background-color: #F2F7FA;
        padding: 24rpx;
        box-sizing: border-box;
        .titel{
            margin-bottom: 16rpx;
            height: 36rpx;
            font-family: PingFang SC, PingFang SC;
            font-weight: 300;
            font-size: 26rpx;
            color: #AAAAB2;
            line-height: 36rpx;
            text-align: left;
            font-style: normal;
            text-transform: none;
        }
        .list{
            margin-bottom: 32rpx;
            background: #FCFDFD;
            box-shadow: 0rpx 8rpx 40rpx 0rpx #E8EBEE;
            border-radius: 0rpx 0rpx 0rpx 0rpx;
            border: 4rpx solid #FFFFFF;
           .list-item{
                transition: 0.2s linear;
               margin:  20rpx 0;
               padding: 0 32rpx;
               display: flex;
               justify-content: space-between;
              .item-left{
                  height: 42rpx;
                  font-family: PingFang SC, PingFang SC;
                  font-weight: 400;
                  font-size: 30rpx;
                  color: #333333;
                  line-height: 42rpx;
                  text-align: left;
                  font-style: normal;
                  text-transform: none;
              } 
              .item-right{
                  height: 42rpx;
                  font-family: PingFang SC, PingFang SC;
                  font-weight: 300;
                  font-size: 30rpx;
                  color: #797980;
                  line-height: 42rpx;
                  text-align: center;
                  font-style: normal;
                  text-transform: none;
              }
           } 
        }
    }
    .itemActive{
           background: #F1F6F9 !important;
    }
</style>